package diploma

import (
	"public_security/controllers"
	"public_security/models"
	"public_security/models/diploma"
)

// 警营之星 API
type DiplomaController struct {
	controllers.BaseController
}

func (i *DiplomaController) Prepare() {
	i.BasePrepare()
}

// @Title create
// @Description 创建奖状
// @Param	body		body 	models.Diploma	 true		"请求参数"
// @Success 200 success
// @router /create [post]
func (i *DiplomaController) Create() interface{} {
	art := new(models.Diploma)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = diploma.Create(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "创建成功")
}

// @Title update
// @Description 修改奖状
// @Param	body		body 	models.Diploma	 true		"请求参数"
// @Success 200 success
// @router /update [post]
func (i *DiplomaController) Update() interface{} {
	art := new(models.Diploma)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = diploma.Update(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "修改成功")
}

// @Title remove
// @Description 删除奖状
// @Param	body		body 	models.Diploma	 true		"请求参数"
// @Success 200 success
// @router /remove [post]
func (i *DiplomaController) Remove() interface{} {
	art := new(models.Diploma)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = diploma.Remove(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "删除成功")
}

// @Title query
// @Description 查询奖状
// @Param	body		body 	models.Diploma	 true		"请求参数"
// @Success 200 {object} models.Diploma
// @router /query [post]
func (i *DiplomaController) Query() interface{} {
	art := new(models.Diploma)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	page := art.GetPageInfoNew()
	results, page := diploma.Query(art, page)
	return i.ToMessageSuccess(results, "查询成功", map[string]interface{}{"pageInfo": page})
}

// @Title createTitle
// @Description 创建奖状称号
// @Param	body		body 	models.DiplomaTitle	 true		"请求参数"
// @Success 200 success
// @router /createTitle [post]
func (i *DiplomaController) CreateTitle() interface{} {
	art := new(models.DiplomaTitle)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = diploma.CreateTitle(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "创建成功")
}

// @Title updateTitle
// @Description 修改奖状称号
// @Param	body		body 	models.DiplomaTitle	 true		"请求参数"
// @Success 200 success
// @router /updateTitle [post]
func (i *DiplomaController) UpdateTitle() interface{} {
	art := new(models.DiplomaTitle)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = diploma.UpdateTitle(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "修改成功")
}

// @Title removeTitle
// @Description 删除奖状称号
// @Param	body		body 	models.DiplomaTitle	 true		"请求参数"
// @Success 200 success
// @router /removeTitle [post]
func (i *DiplomaController) RemoveTitle() interface{} {
	art := new(models.DiplomaTitle)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	err = diploma.RemoveTitle(art)
	if err != nil {
		return i.ToMessageFailed(nil, err.Error())
	}
	return i.ToMessageSuccess(nil, "删除成功")
}

// @Title queryTitle
// @Description 查询奖状称号
// @Param	body		body 	models.DiplomaTitle	 true		"请求参数"
// @Success 200 {object} models.DiplomaTitle
// @router /queryTitle [post]
func (i *DiplomaController) QueryTitle() interface{} {
	art := new(models.DiplomaTitle)
	err := i.RequestJsonScan(&art)
	if err != nil {
		return i.ToMessageFailed(nil, "参数错误")
	}
	results := diploma.QueryTitle(art)
	return i.ToMessageSuccess(results, "查询成功")
}
